package com.apes.fn.tms.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.scm.masterdata.stock.model.PhyDepot;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;


/**
 * 运单规划方案单
 * @author yiny
 * 2020.3.9
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = WaybillRoutePlanning.CONST_TABLE_NAME,uniqueConstraints = {@UniqueConstraint(columnNames = {"plan_number", "waybill_id","execution_number"})})
public class WaybillRoutePlanning extends BaseModel {
    public static final String CONST_TABLE_NAME = "tms_waybill_route_planning";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "运单规划方案单")
    @Comment("编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "waybill_id", referencedColumnName = "id")
    @Comment("运单号")
    private Waybill waybillId;

    @Column(name = "plan_number")
    @Comment("方案号")
    private int planNumber;

    @Column(name = "execution_number")
    @Comment("执行序号")
    private int executionNumber;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "line_id", referencedColumnName = "id")
    @Comment("线路ID")
    private BranchLine lineId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "delivery_address", referencedColumnName = "id")
    @Comment("发货地址")
    private PhyDepot deliveryAddress;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "shipping_address", referencedColumnName = "id")
    @Comment("收货地址")
    private PhyDepot shippingAddress;

    @Column(name = "estimated_delivery_time")
    @Comment("预计送达时间")
    private Date estimatedDeliveryTime;

    @Column(name = "valid", nullable = false, columnDefinition = "number(1, 0) default 0")
    @Comment("有效标记") // 0:初始化, 1:无效, 2:被选择
    private int valid = 0;
}
